$(function(){
  // 文档就绪
  function handleScroll () {
    var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
    var offsetTop = document.querySelector('#searchBar').offsetTop + 80
    if (scrollTop > offsetTop) {
      $('#searchBar').addClass('searchBarFixed')
      // this.searchBarFixed = true
    } else {
      $('#searchBar').removeClass('searchBarFixed')
  
      // this.searchBarFixed = false
    }
    // if (window.scrollY >= 1000) {
    //   this.totop = true
    // } else {
    //   this.totop = false
    // }
  }
  window.addEventListener('scroll', handleScroll)
  function back () {
    var timer = setInterval(() => {
    let h = document.documentElement.scrollTop || document.body.scrollTop;
    let nowH = h
    var speed = (0 - nowH) / 8;                     // 随着高度减速  
    speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);  
    if (h === 0) {                          //当前高度为零,停止这次计时器  
      clearInterval(timer);                             // C1  
    }
    document.documentElement.scrollTop = h + speed
    document.body.scrollTop = h + speed
    }, 10)
  }
  $(".back,.backText").click(function(){
    back()
  })
  $(".consultation,.consultationText").click(function(){
    $('.statement').show()
  })
  $('.close').click(function(){
    $('.statement').hide()
  })
  function map(){
    var map = new AMap.Map("container", {
        resizeEnable: true,
        center: [120.117769,30.275331],
        zoom: 16
    })
    var marker = new AMap.Marker({
      position: [120.117769,30.275331],   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
      // title: '全国'
    })
    map.add(marker)
  }
  map()
});


